package com.dk.controller;


import com.dk.bean.Result;
import com.dk.em.ResultEnum;
import com.dk.pojo.CarBrand;
import com.dk.service.CarBrandService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 张成涛
 * @since 2021-08-12
 */
@RestController
@RequestMapping("/car-brand")
public class CarBrandController {

    @Autowired
    private CarBrandService carBrandService;

    @ApiOperation(value = "品牌查询")
    @GetMapping
    private Result toSelect(){
       List<CarBrand> list = carBrandService.toSelect();
       return Result.buildResult(ResultEnum.SUCCESS).setData(list);
    }

    //es搜索
    @GetMapping("searchBySkuName")
    @ApiOperation(value = "搜索框的搜索查询")
    @ApiImplicitParam(name = "brandName",value = "搜索的关键字",required = false,dataTypeClass = String.class,paramType = "query")
    public Result searchBySkuName(@RequestParam(required = false,value = "brandName")String brandName) throws IOException {
        List<Map<String,Object>> list = carBrandService.searchBySkuName(brandName); //查询数据
        return Result.buildResult(ResultEnum.SUCCESS).setData(list);
    }

}

